From 964da13e758c002576ea61181a77da128cde4818 Mon Sep 17 00:00:00 2001 From: Paul Donald Date: Fri, 3 Oct 2025 16:33:32 +0200 Subject: [PATCH] config: refactor parse_leasetime() - branch amount remains same MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Also make 's' value a noop. Signed-off-by: Paul Donald Link: https://github.com/openwrt/odhcpd/pull/225 Signed-off-by: Álvaro Fernández Rojas --- src/config.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/config.c b/src/config.c index cfc0af6..8a7a9c3 100644 --- a/src/config.c +++ b/src/config.c @@ -431,18 +431,14 @@ static double parse_leasetime(struct blob_attr *c) { double time = strcmp(val, "infinite") ? strtod(val, &endptr) : UINT32_MAX; if (time && endptr && endptr[0]) { - if (endptr[0] == 's') - time *= 1; - else if (endptr[0] == 'm') - time *= 60; - else if (endptr[0] == 'h') - time *= 3600; - else if (endptr[0] == 'd') - time *= 24 * 3600; - else if (endptr[0] == 'w') - time *= 7 * 24 * 3600; - else - goto err; + switch(endptr[0]) { + case 's': break; /* seconds */ + case 'm': time *= 60; break; /* minutes */ + case 'h': time *= 3600; break; /* hours */ + case 'd': time *= 24 * 3600; break; /* days */ + case 'w': time *= 7 * 24 * 3600; break; /* weeks */ + default: goto err; + } } if (time < 60) -- 2.30.2